﻿

using Maticsoft.BLL;
using Maticsoft.DBUtility;
using Maticsoft.Model;
using System;
using System.Data;
using System.Text;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using Wuqi.Webdiyer;

public partial class WebPage_Index_youjiandingyue : SystemBBasePage
{

    private Maticsoft.BLL.Mailer mailer = new Maticsoft.BLL.Mailer();
    private string sql = " 1=1 ";
    private int text = Convert.ToInt32(PageIndex.pageIndex);


    private void delete(int id)
    {
        new Maticsoft.BLL.Mailer().Delete(id);
    }

    private void getYoujianDingyue()
    {
        if ((this.txtcity.Text != null) && (this.txtcity.Text != ""))
        {
            this.sql = this.sql + " and City_id=" + this.txtcity.Text + " ";
        }
        if ((this.txtemail.Text != null) && (this.txtemail.Text != ""))
        {
            this.sql = this.sql + " and email like '" + this.txtemail.Text + "%' ";
        }
        StringBuilder builder = new StringBuilder();
        StringBuilder builder2 = new StringBuilder();
        builder.Append("<tr >");
        builder.Append("<th width='350'>邮件地址</th>");
        builder.Append("<th width='80'>城市</th>");
        builder.Append("<th width='350'>密钥</th>");
        builder.Append("<th width='80'>操作</th>");
        builder.Append("</tr>");
        Maticsoft.BLL.Category category = new Maticsoft.BLL.Category();
        int recordCount = 0;
        DataSet set = DbHelperSQL.Page(this.text, this.pager.CurrentPageIndex, "Mailer", this.sql, "", "*", out recordCount);
        if ((set.Tables.Count > 0) && (set.Tables[0].Rows.Count > 0))
        {
            for (int i = 0; i < set.Tables[0].Rows.Count; i++)
            {
                DataRow row = set.Tables[0].Rows[i];
                if ((i % 2) != 0)
                {
                    builder2.Append("<tr>");
                }
                else
                {
                    builder2.Append("<tr class='alt'>");
                }
                builder2.Append("<td nowrap>" + row["Email"].ToString() + "</td>");
                if (category.GetModelList("Id=" + row["City_id"]).Count > 0)
                {
                    foreach (Maticsoft.Model.Category category2 in category.GetModelList("Id=" + row["City_id"].ToString()))
                    {
                        builder2.Append("<td nowrap>" + category2.Name + "</td>");
                    }
                }
                else
                {
                    builder2.Append("<td nowrap>全国</td>");
                }
                builder2.Append("<td nowrap>" + row["Secret"].ToString() + "</td>");
                builder2.Append("<td class='op' nowrap>");
                builder2.Append(string.Concat(new object[] { "<a class=\"remove-record\" href='Index-youjiandingyue.aspx?remove=", row["Id"].ToString(), "&pageIndex=", this.pager.CurrentPageIndex, "&where=", DESEncrypt.Encrypt(this.sql, "type"), "'  >删除</a>" }));
                builder2.Append("</td>");
                builder2.Append("</tr>");
            }
        }
        this.Literal1.Text = builder.ToString();
        this.Literal2.Text = builder2.ToString();
        this.pager.RecordCount = recordCount;
    }

    protected override void OnLoad(EventArgs e)
    {
        base.OnLoad(e);
        this.HeaderControl1.Select = "index";
        if (!base.IsPostBack && (base.Request.QueryString["remove"] != null))
        {
            this.delete(int.Parse(base.Request.QueryString["remove"].ToString()));
            base.SetSuccess("删除成功");
            if ((base.Request.QueryString["pageIndex"] != null) && (base.Request.QueryString["pageIndex"].ToString() != ""))
            {
                this.pager.CurrentPageIndex = Convert.ToInt32(base.Request.QueryString["pageIndex"].ToString());
            }
            if ((base.Request.QueryString["where"] != null) && (base.Request.QueryString["where"].ToString() != ""))
            {
                this.sql = DESEncrypt.Decrypt(base.Request.QueryString["where"].ToString(), "type");
            }
        }
        if (base.Request.HttpMethod == "POST")
        {
            this.getYoujianDingyue();
        }
        this.getYoujianDingyue();
    }

    protected void pager_PageChanged(object sender, EventArgs e)
    {
        this.getYoujianDingyue();
    }
}


